<?php
$page_title="Manage Email Group";
include("includes/header.php");
$groupId=$_REQUEST["gid"];
$mode=$_GET["mode"];

$query = "SELECT * FROM bkitc_profiles where rec_status=1";
$membersList=qry_data($query." order by  registrant_id ");
$groupMembersList=qry_data("SELECT M.*,L.* FROM bkitc_email_group_map L join  bkitc_profiles M on L.fk_member_id=M.registrant_id where L.fk_group_id='".$groupId."'");

	if($mode=="edit")
	{	$groupInfo=qry_data("select * from bkitc_email_group where group_id=".$groupId);
		$group=$groupInfo[0];
	}


	if($mode=="del" || $mode=="active"){
	$activeSts=0;
	if($mode=="active") $activeSts=1;
	exec_qry("update bkitc_email_group set rec_status=$activeSts where group_id=".$groupId);//Soft Delete
	header("location:registrants.php");
	
	}
?>
<div class="fleft">
<ul class="subMenu">

<li><a href="edit_group.php?mode=add">Add New group</a></li>
</ul>
</div>
<div class="cleardiv"></div>
<div style="width:100%" class="content_bg">

<form method="post" action="edit_email_pro.php?gid=<?=$_GET["gid"]?>" enctype="multipart/form-data" onsubmit="return validateRegistration(this)">

<table cellspacing="3" cellpadding="3">
<tr>
	<td colspan="2">Email Group Name&nbsp;* <input name="group_name" id="group_name" size="50" value="<?=$group["group_name"];?>"  type="text" class="txtbox"	 /></td>
	
</tr>

<tr><td  valign="top">Description <br><textarea class="txtarea" name="group_desc" id="group_desc" rows="4" cols="37"><?=$group["group_desc"];?></textarea></td>
<td  valign="top">Remarks <br><textarea class="txtarea" name="group_remarks" id="group_remarks" rows="4" cols="37"><?=$group["group_remarks"];?></textarea></td></tr>
<tr>
<td colspan="2"><b>Map Members :</b> [ To map multiple member, please hold ctrl key and select ]</td></tr>
<tr>
<td colspan="2" valign="top">
	<select multiple="true" style="width:600px;height:auto;" name="group_member[]" class="selectbox">
	<?foreach($membersList as $i=>$member) { ?>
		<option value="<?=$member["registrant_id"]?>">BKITC<?=number_pad($member["registrant_id"],5)." : ".$member["full_name"]." : ".$member["email_id"]." - ".$member["alternate_email_id"]?></option>

	<? } ?>
	</select>
	<input type="submit" class="button" value="Add selected member(s) to list"/>
	</td>
</tr>
<tr>
<td colspan="2">
<table cellpadding="5" cellspacing="0" style="border:1px solid #666;" width="100%">
<tr bgcolor="#aeaeae" align="left">
<th>No</th>
<th>Member ID</th>
<th>Name</th>
<th>Email ID</th>
<th>Alternate Email ID</th>
<th>Delete</th>
</tr>
<?foreach($groupMembersList as $i=>$grp_member) { ?>
	<tr bgcolor="#f2f2f2" align="left">
		<td><?=$i+1?></td>
		<td>BKITC<?=number_pad($grp_member["registrant_id"],5);?></td>
		<td><?=$grp_member["full_name"];?></td>
		<td><?=$grp_member["email_id"];?></td>
		<td><?=$grp_member["alternate_email_id"];?></td>
		<td><a  href="javascript:if(confirm('Are you sure to remove this member from this email group?')) location.href='edit_email_pro.php?mode=del_member&gid=<?=$grp_member["fk_group_id"]?>&mid=<?=$grp_member["fk_member_id"]?>'";>Remove</a></td>
	</tr>	
<? } ?>
</table>

</td>


</tr>



</tbody>
</table>
<hr/>
<div style="float:right;" >
<?$btnCaption=" Save group Info "; if($mode=="add") $btnCaption=" Add group "; ?>

<input type="submit" class="button"  value="<?=$btnCaption?>">



<input onclick="location.href='email_list.php'"  type="button" class="button" value=" Back to group List">
<br>
<br>
</div>
</form>
</div>

<script language="javascript">
$("link3").className="activeMenu";
</script>

<? include("includes/footer.php");?>



